
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        if (uname == null || "".equals(uname.trim())) {
            request.setAttribute("msg", "用户姓名不能为空！");
            request.getRequestDispatcher("login-01.jsp").forward(request, response);
            return;
        }
        if (upwd == null || "".equals(upwd.trim())) {
            request.setAttribute("msg", "密码不能为空！");
            request.getRequestDispatcher("login-01.jsp").forward(request, response);
            return;
        }
        if (!"zhangsan".equals(uname) || !"123456".equals(upwd)) {
            request.setAttribute("msg", "密码错误！");
            request.getRequestDispatcher("login-01.jsp").forward(request, response);
            return;
        } else {
            request.getSession().setAttribute("uname", uname);
            response.sendRedirect("login-02.jsp");
        }

    }
}